# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=twisted_iocpsupport
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=25.2.0
pkgrel=1
pkgdesc='An extension for use in the twisted I/O Completion Ports reactor (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/twisted-iocpsupport'
)
license=('spdx:MIT')
url='https://github.com/twisted/twisted-iocpsupport'
depends=(${MINGW_PACKAGE_PREFIX}-python)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-fix-multiple-defs.patch)
sha256sums=('6fc1650eac1f342ebc974fc969c6de1658dc2e051c2bd11fa4a4a6fe4fe11f89'
            '615fe6e1ee621eafc69faefcada30258eb0692df44afac7020c29bf1555de958')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-multiple-defs.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  CFLAGS+=" -Wno-int-conversion -Wno-error=incompatible-pointer-types"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
